{% extends 'pages/_base.html' %}

{% block _base %}

{% from 'tools/card.html' import nonModal %}
{% from 'tools/tabpages.html' import tabPages %}
{% from 'tools/table.html' import table %}

{% set unpublished_data = [] %}
{% set unchecked_data = [] %}
{% set unpassed_data = [] %}
{% set passed_data = [] %}

{% for row in data.unchecked.Blog %}
    {% set _ = row.update({
        'title': '<a href="' ~ url_for("post.get_anyone_page_of_blog", pid=row.id) ~ '">' ~ row.title ~ '</a>',
        'edit': '<a href="' ~ url_for("post.get_my_page_of_update_blog", pid=row.id) ~ '" class="btn btn-sm btn-primary">修改</a>',
        'delete': '<form action="' ~ url_for("post.post_my_model_of_delete_blog", pid=row.id) ~ '" method="POST" style="display:inline;">'
                  ~ '<button type="submit" class="btn btn-sm btn-primary">删除</button>'
                  ~ '</form>',
    }) %}
    {% set _ = unchecked_data.append(row) %}
{% endfor %}

{% for row in data.unpassed.Blog %}
    {% set _ = row.update({'title': '<a href="' ~ url_for("post.get_anyone_page_of_blog", pid=row.id) ~ '">' ~ row.title ~ '</a>'}) %}
    {% set _ = unpassed_data.append(row) %}
{% endfor %}

{% for row in data.passed.Blog %}
    {% set _ = row.update({
        'title': '<a href="' ~ url_for("post.get_anyone_page_of_blog", pid=row.id) ~ '">' ~ row.title ~ '</a>',
        'delete': '<form action="' ~ url_for("post.post_my_model_of_delete_blog", pid=row.id) ~ '" method="POST" style="display:inline;">'
                  ~ '<button type="submit" class="btn btn-sm btn-primary">删除</button>'
                  ~ '</form>'
    }) %}
    {% set _ = passed_data.append(row) %}
{% endfor %}

{% set tabs = [
    {'tabname': '未审核', 'html': table(required={'title': '标题', 'time': '日期', 'edit': '修改', 'delete': '删除'}, data=unchecked_data)},
    {'tabname': '已通过', 'html': table(required={'title': '标题', 'time': '日期', 'delete': '删除'}, data=passed_data)},
    {'tabname': '已驳回', 'html': table(required={'title': '标题', 'time': '日期', 'reason': '驳回原因'}, data=unpassed_data)}
] %}

{{ nonModal(
    head='<h4>帖子管理</h4>',
    collapse=False,
    body=tabPages(tabs)
) }}





{% set comment_data = [] %}
{% for comment in data.Comment %}
    {% set _ = comment_data.append({
        'username': '<a href="' ~ url_for("personal.get_anyone_page_of_personal", uid=comment.User[0].id) ~ '">' ~ comment.User[0].username ~ '</a>',
        'title': '<a href="' ~ url_for("post.get_anyone_page_of_blog", pid=comment.Blog[0].id) ~ '">' ~ comment.Blog[0].title ~ '</a>',
        'time': comment.time,
        'content': comment.content,
        'delete': '<form action="' ~ url_for("post.post_my_model_of_delete_comment", cid=comment.id) ~ '" method="POST" style="display:inline;">'
                  ~ '<button type="submit" class="btn btn-sm btn-primary">删除</button>'
                  ~ '</form>',
    }) %}
{% endfor %}



{{ nonModal(
    head='<h4>评论管理</h4>',
    collapse=False,
    body=table(required={'username':'作者','title':'标题','time':'日期','content':'我的评论','delete': '操作'},data=comment_data)
) }}

{% endblock %}
